package com.factory.simple_factory;

import com.factory.askQuestion.piza.BasePiza;
import com.factory.askQuestion.piza.CheesePiza;
import com.factory.askQuestion.piza.GreekPizza;
import com.factory.askQuestion.piza.PepperPiza;

/**
 * 简单工程模式
 */
public class SimpleFactory {

    public static BasePiza createPizza(String pizaType) {
        BasePiza piza = null;
        System.out.println("简单工厂模式开始创建对象");
        //根据类型创建piza
        if (pizaType.equals("greek")) {//如果要订购希腊披萨，创建一个希腊披萨
            piza = new GreekPizza();
            piza.setName("希腊披萨");
        } else if (pizaType.equals("cheese")) {
            piza = new CheesePiza();
            piza.setName("奶酪披萨");
        } else if (pizaType.equals("pepper")) {
            piza = new PepperPiza();
            piza.setName("胡椒披萨");
        } else {
            throw new RuntimeException("没有该类型的piza");
        }
        return piza;
    }

}
